<?php
class Response{
    /**
     * 重定向
     * @param string $url
     * @return void
     */
    public static function redirect(string $url){
        header("Location: $url");
        exit;
    }

    /**
     * 设置返回json
     * @param array $data
     * @return void
     * @throws Exception
     */
    public static function returnJson(array $data)
    {
        header('Content-Type: application/json');
        echo json_encode($data);
        exit;
    }


    /**
     * 弹窗并跳转
     * @param string $msg
     * @param string $url
     */
    public static function alertRedirect(string $msg, string $url)
    {
        echo "<script>alert('$msg');location.href='$url'</script>";
        exit;
    }

    public static function alertRedirectView(string $msg,string $view){
        echo "<script>alert('$msg');location.href='/admin/index.php?view=$view'</script>";
        exit;
    }

    public static function alertBack(string $msg){
        echo "<script>alert('$msg');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
        exit;
    }


    /**
     * 弹窗alert
     * @param string $msg
     */
    public static function alert(string $msg){
        echo "<script>alert('$msg');</script>";
    }

}